package com.ljf.finance.domain.validator;

import com.ljf.common.domain.validator.BasisValidator;
import com.ljf.common.exception.ServiceException;
import com.ljf.finance.domain.repository.FinanceDatVirtualAccountRepository;
import com.ljf.finance.dto.command.FinanceDatVirtualAccountCommand;
import com.ljf.finance.dto.query.FinanceDatVirtualAccountQuery;
import com.ljf.finance.model.FinanceDatVirtualAccount;
import com.ljf.finance.vo.FinanceDatVirtualAccountVO;
import org.springframework.stereotype.Component;

/**
 * 虚拟账户定义  业务校验
 *
 * @author LJF
 * @since 2024-02-20
 */
@Component
public class FinanceDatVirtualAccountValidator extends BasisValidator<FinanceDatVirtualAccountQuery, FinanceDatVirtualAccountCommand, FinanceDatVirtualAccountVO, FinanceDatVirtualAccount, FinanceDatVirtualAccountRepository> {

    @Override
    public void checkAdd(FinanceDatVirtualAccountCommand command) throws ServiceException {
        super.checkAdd(command);
        if (repository.count(FinanceDatVirtualAccountQuery.builder().name(command.getName()).build()) > 0) {
            throw new ServiceException("虚拟账户新增校验异常: 账户名称已存在");
        }
    }

    /**
     * 常用账户查询  业务校验
     *
     * @param query
     * @throws ServiceException
     */
    public void checkQueryCommonUsed(FinanceDatVirtualAccountQuery query) throws ServiceException {
        super.checkQueryList(query);
    }

}
